﻿using FRMS.DAL;
using FRMS.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FRMS.BUS
{
    public class MenuBUS
    {
        public ResponseMessage AddMenu(MenuInfo menuInfo)
        {
            ResponseMessage message = new ResponseMessage();
            MenuDAL da = new MenuDAL();
            bool result = da.AddMenu(menuInfo);
            if (result)
            {
                message.errcode = 0;
                message.errmsg = "";
            }
            else
            {
                message.errcode = 1;
                message.errmsg = "新增菜单失败";
            }
            return message;
        }

        public ResponseMessage EditMenu(MenuInfo menuInfo)
        {
            ResponseMessage message = new ResponseMessage();
            MenuDAL da = new MenuDAL();
            bool result = da.EditMenu(menuInfo);
            if (result)
            {
                message.errcode = 0;
                message.errmsg = "";
            }
            else
            {
                message.errcode = 1;
                message.errmsg = "修改菜单失败";
            }
            return message;
        }

        public ResponseMessage DeleteMenu(MenuInfo menuInfo)
        {
            ResponseMessage message = new ResponseMessage();
            MenuDAL da = new MenuDAL();
            bool result = da.DeleteMenu(menuInfo);
            if (result)
            {
                message.errcode = 0;
                message.errmsg = "";
            }
            else
            {
                message.errcode = 1;
                message.errmsg = "删除菜单失败";
            }
            return message;
        }

        public ResponseMessage QueryMenu(MenuInfo menuInfo)
        {
            ResponseMessage message = new ResponseMessage();
            MenuDAL da = new MenuDAL();
            List<MenuInfo> list = da.QueryMenu(menuInfo);
            message.errcode = 0;
            message.data = list;
            message.total = da.QueryMenuCount(menuInfo);
            message.errmsg = "";

            return message;
        }

        public ResponseMessage LoadMenu(MenuInfo menuInfo)
        {
            ResponseMessage message = new ResponseMessage();
            MenuDAL da = new MenuDAL();
            MenuInfo info = da.LoadMenu(menuInfo);
            message.errcode = 0;
            message.data = info;
            message.errmsg = "";

            return message;
        }

        public ResponseMessage QueryAllMenu()
        {
            ResponseMessage message = new ResponseMessage();
            MenuDAL da = new MenuDAL();
            List<MenuList> menuLists = da.GetParentMenu();
            foreach (var item in menuLists)
            {
                item.child = da.GetChildMenu(item.ID);
            }
            message.data = menuLists;
            return message;

        }
    }
}
